package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Title;
import com.woniuxy.entity.dto.TitleDto;
import com.woniuxy.service.TitleService;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TitleController
 * @Description TODO
 * @Author 冯浩波
 * @Date 2022/3/12 15:21
 */
@RestController
@RequestMapping("/title")
public class TitleController {
    @Autowired
    TitleService titleService;
//    //添加试题
//    @RequestMapping("/addOne/{topicid}")
//    public ResponseEntity addTitle(@RequestBody TitleDto titleDto,@PathVariable("topicid") int topicid){
//        System.out.println(titleDto.toString());
//        System.out.println(topicid);
//        return titleService.addTitle(titleDto,topicid);
//    }
    //添加试题
    @ApiOperation(value = "添加试题")
    @RequestMapping("/addTitle/")
    public ResponseEntity addTitle(@RequestBody Title title){
        return titleService.addTitle(title);
    }

    //删除试题
    @ApiOperation(value = "删除试题")
    @RequestMapping("/deleteTitle/{id}")
    public ResponseEntity deleteTitle(@PathVariable("id") int id){
        return titleService.deleteTitle(id);
    }

    //修改试题
    @ApiOperation(value = "修改试题")
    @RequestMapping("/updateTitle/")
    public ResponseEntity updateTitle(@RequestBody Title title){
        return  titleService.updateTitle(title);
    }

    //查找试题
    @ApiOperation(value = "查看试题")
    @RequestMapping("/findTitle/{currentPage}/{pageSize}")
    public ResponseEntity findTitle(@PathVariable("currentPage")int currentPage,@PathVariable("pageSize") int pageSize,@RequestBody Title title){
        return titleService.findTitle(currentPage,pageSize,title);
    }

    //查找试卷id
    @ApiOperation(value = "查找试卷id")
    @RequestMapping("/findTopicId/{trainingid}")
    public ResponseEntity findTopicId(@PathVariable("trainingid")int trainingid){
        return titleService.findTopicID(trainingid);
    }

}
